package com.guofen.controller.cylj;

import com.guofen.pojo.KitchenwasteHatching;
import com.guofen.service.cylj.KitchenwasteHatchingService;
import com.guofen.util.DateAndTimeUtil;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api("厨余垃圾黑水虻就地处理站虫卵孵化记录表")
public class KitchenwasteHatchingController {
    @Resource
    private KitchenwasteHatchingService kitchenwasteHatchingService;

    @ApiOperation("提交厨余垃圾黑水虻就地处理站虫卵孵化记录")
    @PostMapping("/kitchenwaste/hatching/add")
    public Result add(@ApiParam(name = "incomingDate",value = "到货日期",required = true) @RequestParam String incomingDate,
                      @ApiParam(name = "incomingWeek",value = "星期",required = true) @RequestParam String incomingWeek,
                      @ApiParam(name = "hatchingDate",value = "孵化日期",required = true) @RequestParam String hatchingDate,
                      @ApiParam(name = "wormOutDate",value = "出虫日期",required = true) @RequestParam String wormOutDate,
                      @ApiParam(name = "hatchingBoxNum",value = "孵化盒号",required = true) @RequestParam String hatchingBoxNum,
                      @ApiParam(name = "hatchingDays",value = "孵化天数",required = true) @RequestParam String hatchingDays,
                      @ApiParam(name = "wormOutBatches",value = "分虫份数",required = true) @RequestParam String wormOutBatches,
                      @ApiParam(name = "weight_1_4",value = "1-4d孵化料重",required = true) @RequestParam String weight_1_4,
                      @ApiParam(name = "weight_5_6",value = "5-6d培育料重",required = true) @RequestParam String weight_5_6,
                      @ApiParam(name = "weight_7_8",value = "7-8d培育料重",required = true) @RequestParam String weight_7_8,
                      @ApiParam(name = "wormEggWeight",value = "孵化虫卵重",required = true) @RequestParam String wormEggWeight,
                      @ApiParam(name = "allFeedWeight",value = "单份虫+料总重",required = true) @RequestParam String allFeedWeight,
                      @ApiParam(name = "remark",value = "备注") @RequestParam(defaultValue = "") String remark,
                      @ApiParam(name = "recorder",value = "记录人",required = true) @RequestParam String recorder){
        int hatchingBoxNum_int = Integer.parseInt(hatchingBoxNum);
        int hatchingDays_int = Integer.parseInt(hatchingDays);
        double weight_1_4_double = Double.parseDouble(weight_1_4);
        double weight_5_6_double = Double.parseDouble(weight_5_6);
        double weight_7_8_double = Double.parseDouble(weight_7_8);
        double wormEggWeight_double = Double.parseDouble(wormEggWeight);
        if (kitchenwasteHatchingService.add(new KitchenwasteHatching(DateAndTimeUtil.getDate(),incomingDate,incomingWeek,hatchingDate,wormOutDate,hatchingBoxNum_int,hatchingDays_int,wormOutBatches,weight_1_4_double,weight_5_6_double,weight_7_8_double,wormEggWeight_double,allFeedWeight,remark,recorder))){
            return ResultGenerator.genSuccessResult();
        }else {
            return ResultGenerator.genFailResult("保存失败");
        }
    }
    @ApiOperation("获取 当日 最新 一条记录")
    @GetMapping(value = "/kitchenwaste/hatching/getlast")
    public Result getlast(){
        return  ResultGenerator.genSuccessResult(kitchenwasteHatchingService.getlast());
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/kitchenwaste/hatching/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(kitchenwasteHatchingService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/kitchenwaste/hatching/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name = "incomingDate",value = "到货日期",required = true) @RequestParam String incomingDate,
                         @ApiParam(name = "incomingWeek",value = "星期",required = true) @RequestParam String incomingWeek,
                         @ApiParam(name = "hatchingDate",value = "孵化日期",required = true) @RequestParam String hatchingDate,
                         @ApiParam(name = "wormOutDate",value = "出虫日期",required = true) @RequestParam String wormOutDate,
                         @ApiParam(name = "hatchingBoxNum",value = "孵化盒号",required = true) @RequestParam String hatchingBoxNum,
                         @ApiParam(name = "hatchingDays",value = "孵化天数",required = true) @RequestParam String hatchingDays,
                         @ApiParam(name = "wormOutBatches",value = "分虫份数",required = true) @RequestParam String wormOutBatches,
                         @ApiParam(name = "weight_1_4",value = "1-4d孵化料重",required = true) @RequestParam String weight_1_4,
                         @ApiParam(name = "weight_5_6",value = "5-6d培育料重",required = true) @RequestParam String weight_5_6,
                         @ApiParam(name = "weight_7_8",value = "7-8d培育料重",required = true) @RequestParam String weight_7_8,
                         @ApiParam(name = "wormEggWeight",value = "孵化虫卵重",required = true) @RequestParam String wormEggWeight,
                         @ApiParam(name = "allFeedWeight",value = "单份虫+料总重",required = true) @RequestParam String allFeedWeight,
                         @ApiParam(name = "remark",value = "备注") @RequestParam(defaultValue = "") String remark) {
        int hatchingBoxNum_int = Integer.parseInt(hatchingBoxNum);
        int hatchingDays_int = Integer.parseInt(hatchingDays);
        double weight_1_4_double = Double.parseDouble(weight_1_4);
        double weight_5_6_double = Double.parseDouble(weight_5_6);
        double weight_7_8_double = Double.parseDouble(weight_7_8);
        double wormEggWeight_double = Double.parseDouble(wormEggWeight);

        return ResultGenerator.genSuccessResult(kitchenwasteHatchingService.update(new KitchenwasteHatching(DateAndTimeUtil.getDate(),incomingDate,incomingWeek,hatchingDate,wormOutDate,hatchingBoxNum_int,hatchingDays_int,wormOutBatches,weight_1_4_double,weight_5_6_double,weight_7_8_double,wormEggWeight_double,allFeedWeight,remark,null)));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/kitchenwaste/hatching/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(kitchenwasteHatchingService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(kitchenwasteHatchingService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}
